﻿using ARchGL.Platform.Electrocar.Core;
using OfficeOpenXml;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;

namespace ARchGL.Platform.Electrocar.Application.Utils
{
    public class OfficeHelper<T> where T : new()
    {
        /// <summary>
        /// 获取 Excel Sheet 数据集合
        /// </summary>
        /// <param name="path">文件路径</param>
        /// <param name="index">Sheets下标，可选参数默认 1</param>
        /// <returns></returns>
        public T[] GetSheetValues(string path, int index = 1)
        {
            var file = new FileInfo(path);
            if (file == null) return null;

            using (var package = new ExcelPackage(file))
            {
                var worksheet = package.Workbook.Worksheets[index];

                var result = worksheet.ConvertSheetToObjects<T>().ToArray();
                return result;
            }
        }
    }

    public class Excels
    {
        /// <summary>
        /// 分别对应表中的列名
        /// </summary>
        [ExcelColumn("Name")]
        public string Name { get; set; }
        [ExcelColumn("Level")]
        public string Level { get; set; }
        [ExcelColumn("Sort")]
        public string Sort { get; set; }
        [ExcelColumn("Code")]
        public string Code { get; set; }
    }
}
